<%@page import="com.biz.ShopCartBizImpl"%>
<%@page import="com.entity.ShopCart"%>
<%@page import="com.entity.UserInfo"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	UserInfo us=(UserInfo)session.getAttribute("loger");
	if(us==null){
		%>
		<script>alert("登录之后才能添加商品到购物车");parent.location="../../login.jsp";</script>
		<%
	}else{
		int stock=Integer.parseInt(request.getParameter("stock"));
		int num=Integer.parseInt(request.getParameter("num"));
		if(stock<num){
		%>
			<script>alert("库存不足,添加到购物车失败");history.back();</script>
		<%	
		}else{
			int pid=Integer.parseInt(request.getParameter("pid"));
			int uid=us.getId();
			double price=Double.parseDouble(request.getParameter("price"));
			String comments=request.getParameter("comments");
			ShopCart sc=new ShopCart();
			sc.setPid(pid);
			sc.setUid(uid);
			sc.setPrice(price);
			sc.setNum(num);
			sc.setComments(comments);
			if(new ShopCartBizImpl().addShopCart(sc)>0){
			%>
				<script>alert("成功添加到购物车");location="../showMyShopCart.jsp";</script>
			<%
			}
		}
	}
%>
